package com.wp.land.start;

import com.wp.land.context.VDataContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2019/05/09
 * @Modified By:
 */

@Component
public class StartupRunner implements CommandLineRunner {


    private static Logger logger = LoggerFactory.getLogger(StartupRunner.class);

    @Override
    public void run(String... strings) throws Exception {
        logger.info("系统初始化开始...");
        testDataV();

        testDataV_1();

        testDataV_2();
    }


    public void testDataV(){
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
        //循环周期执行
        scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                int step = (VDataContext.citys+1) % 3;
                VDataContext.citys = step;
                System.out.println("city:"+VDataContext.citys);
            }
        }, 1, 30, TimeUnit.SECONDS);
    }

    public void testDataV_1(){
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
        //循环周期执行
        scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                int step = (VDataContext.envIndex+1) % 3;
                VDataContext.envIndex = step;
                System.out.println("envIndex:"+VDataContext.envIndex);
            }
        }, 1, 5, TimeUnit.SECONDS);
    }

    public void testDataV_2(){
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
        //循环周期执行
        scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                int step = (VDataContext.cityIndex+1) % 2;
                VDataContext.cityIndex = step;
                System.out.println("cityIndex:"+VDataContext.cityIndex);
            }
        }, 1, 15, TimeUnit.SECONDS);
    }
}
